//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
	components: {//动态扩充组件或组件路径
		//表单header、content、footer对应位置扩充的组件
		gridHeader:'',//{ template: "<div>扩展组xx件</div>" },
		gridBody: '',
		gridFooter: '',
		//弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
		modelHeader: '',
		modelBody: '',
		modelFooter: '',
		type:'',
	},
	buttons: {view: [], box:[],  detail:[]},//扩展的按钮
	methods: {//事件扩展
		getFormOption(field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        });
      });
      return option;
    },
		onInit() {
			this.columns.push({
        title: '操作',
        fixed: 'right',
        width: 100,
        render: (h, { row, column, index }) => {
          return h(
            "div", { style: {} }, [
            h(
              "a", {
              props: {},
              style: { "margin-left": "10px" },
              on: {
                click: (e) => {
                  // console.log(row, "----")
                  this.$router.push({
                    name: "V_productbydate",
                    params: {
                      id: row.id,
                      type: 3
                    }
                  })
                }
              }
            },
              "价格日历"
            ),
          ])
        }
      })
			const supplierCode = this.getFormOption("supplierCode");
			const scenic_poiId = this.getFormOption("scenic_poiId");
			// const partlyRefund = this.getFormOption("partlyRefund");
			// const refundType = this.getFormOption("refundType");
			// if(this.currentAction == "Add"){
			// 	type.hidden = false
			// 	typename.hidden = true
			// }else{
			// 	this.editFormFields.timeContainer = [ this.editFormFields.effectiveStartDate,this.editFormFields.effectiveEndDate ]
			// 	type.hidden = true
			// 	typename.hidden = false
			// }
			// partlyRefund.onChange = (kay,ele)=>{
			// 	if(kay === 0){
			// 		this.editFormFields.refundType = 4
			// 		refundType.hidden = true
			// 	}else{
			// 		this.editFormFields.refundType = ''
			// 		refundType.hidden = false
			// 	}
			// }
			scenic_poiId.hidden = true
			supplierCode.onChange = (kay,ele)=>{
				if(kay){
					scenic_poiId.hidden = false
					scenic_poiId.data = this.getScenic(kay)
          console.log("%c 🚎: supplierCode.onChange -> this.getScenic(kay) ", "font-size:16px;background-color:#bfd234;color:black;", this.getScenic(kay))
				}else{
					scenic_poiId.hidden = true
					this.editFormFields.scenic_poiId = ''
				}
			}
		},
		getScenic(val){
			let a = []
			let params = {"page":1,"rows":10000,"sort":"id","order":"desc","wheres":`[{"name":"scenic_supplierid","value":${val},"displayType":"select"}]`}
      this.http.post("/api/Mall_procure_scenic/getPageData", params).then(res => {
				res.rows.forEach(i => {
					a.push({key: i.scenic_poiId,value: i.scenic_name})
				})
      });
			return a
		},
		modelOpenAfter(row){
      console.log("%c 📸: modelOpenAfter -> row ", "font-size:16px;background-color:#ac96c5;color:white;", row)
			//弹窗打开之后
			const scenic_poiId = this.getFormOption("scenic_poiId");
			if(this.currentAction == "Add"){
			}else{
				const type = this.getFormOption("type");
				scenic_poiId.hidden = false
				type.required = false
				scenic_poiId.data = this.getScenic(row.supplierCode)
				this.type = row.type
				this.editFormFields.scenic_poiId = row.scenic_poiId
				this.editFormFields.timeContainer = [ row.effectiveStartDate,row.effectiveEndDate ]
				this.editFormFields.timeContainer = [ row.effectiveStartDate,row.effectiveEndDate ]
			}
		},
		modelOpenBefore(row){
			//弹窗打开之前
			const type = this.getFormOption("type"); //场次
			const typename = this.getFormOption("typename"); //场次
			if(this.currentAction == "Add"){
				type.hidden = false
				typename.hidden = true
			}else{
				type.hidden = true
				typename.hidden = false
			}
		},
		addBefore(formData) {
      //新建保存前formData为对象，包括明细表
			formData.mainData.isDelete = 0;
			formData.mainData.effectiveStartDate = this.editFormFields.timeContainer[0]
			formData.mainData.effectiveEndDate = this.editFormFields.timeContainer[1]
			return formData
    },
		updateBefore(formData){
			formData.mainData.type = this.type
			//编辑保存前formData为对象，包括明细表
			formData.mainData.isDelete = 0;
			formData.mainData.effectiveStartDate = this.editFormFields.timeContainer[0]
			formData.mainData.effectiveEndDate = this.editFormFields.timeContainer[1]
			return formData
		}
	}
};
export default extension;